<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>后台管理系统</title>
        <meta name="author" content="BaiYY"/>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
        <meta name="renderer" content="webkit">
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
        <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
    </head>
<body>
    <div class="right-sidebar" style="max-width: 1200px;">
        <ul class="nav nav-tabs" style="margin-bottom: 16px" role="tablist" id="listTab">
            <li role="presentation" id="lispec"><a href="contentNotice.html">{:L(GAME_SETTING_NOTICE)}</a></li>
            <li role="presentation" id="contactd"><a href="contentContact.html">{:L(GAME_SETTING_CONTACT)}</a></li>
            <li role="presentation" id="messaged"><a href="contentMessage.html">{:L(GAME_SETTING_MESSAGE)}</a></li>
            <li role="presentation" id="msgpushd" class="active" ><a href="msgPush.html">{:L(GAME_MSGPUSH)}</a></li>
        </ul>
        <div class="panel panel-default">
            <div class="panel-heading"><strong>消息推送内容</strong></div>
            <div class="panel-body">
                <div>
                    <p>推送标题 <span style="float: right">标题最多20个字</span></p>
                    <input type="text" class="form-control" name="title" id="title">
                </div>
                <div style="margin-top: 10px;">
                    <p>推送内容<span style="float: right">标题最多60个字</span></p>
                    <input type="text" class="form-control" name="cbody" id="cbody">
                </div>
                <p class="text-center" style="margin-top: 10px;"><button class="btn btn-primary" id="cbtn">修改</button></p>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {
            var contactd = $.trim($("#contactd").text());
            var messaged = $.trim($("#messaged").text());
            var msgpushd = $.trim($("#msgpushd").text());

            if(contactd == '' || contactd == 'GAME_SETTING_CONTACT') {
                $("#contactd").hide();
            }

            if(messaged == '' || messaged == 'GAME_SETTING_MESSAGE') {
                $("#messaged").hide();
            }

            if(msgpushd == '' || msgpushd == 'GAME_MSGPUSH') {
                $("#msgpushd").hide();
            }
            $.ajax({
                type:'get',
                url:"{:U('Admin/Main/getMsgPush')}",
                success: function (data) {
                    if(data != 'error') {
                        $("#title").val(data.title);
                        $("#cbody").val(data.body);
                    }else if(data == 'error') {
                        alert("请求错误！");
                    }
                }
            })
            
            $("#title").blur(function () {
                if($.trim($("#title").val()).length>20) {
                    alert("标题最大长度是20个字");
                    window.location.href="{:U('Admin/Main/msgPush')}";
                    return false;
                }
            });
            $("#cbody").blur(function () {
                if($.trim($("#cbody").val()).length>60) {
                    alert("内容最大长度是60个字");
                    window.location.href="{:U('Admin/Main/msgPush')}";
                    return false;
                }
            });
            
            $("#cbtn").on('click',function () {
                var title = encodeURI($.trim($("#title").val()));
                var cbody = encodeURI($.trim($("#cbody").val()));

                if(title == '' || cbody == '') {
                    alert("未设置标题和内容，不能修改！");
                    window.location.href="{:U('Admin/Main/msgPush')}";
                    return false;
                }
                $.ajax({
                    type:'post',
                    url:"{:U('Admin/Main/setMsgPush')}",
                    dataType:'json',
                    data:{'title':title,'cbody':cbody},
                    success:function (data) {
                        if(data == 'success') {
                            alert("设置成功");
                            window.location.href="{:U('Admin/Main/msgPush')}";
                        }else if(data == 'error') {
                            alert("设置失败！");
                            window.location.href="{:U('Admin/Main/msgPush')}";
                        }
                    }
                })
            })
        })
    </script>
</body>
</html>